package basemod

import (
	"time"

	"gitee.com/wint/go-csbuf/csbuf"
	"gitee.com/wint/tge/session"
)

type IMsgPack interface {
	GetMsg() 	csbuf.CsbufMessage
	GetSes() 	*session.Session

	SetMsg(csbuf.CsbufMessage)
	SetSes(*session.Session)

	Send(csbuf.CsbufMessage)
}

type IRecver interface {
	OnRecv(IMsgPack)
}

// 网络默认响应接口定义
type IDefaultModREQ interface {
	OnDefaultREQ(IMsgPack)	uint16
}

// 帧刷新接口定义
type IUpdater interface {
	Update(time.Duration)
}

// 获取传输数据
type IToData interface {
	ToData(playerId int32) csbuf.CsbufMessage
}

// 错误定义
type Err struct {
	Proto uint16 `json:"proto"`
	Code uint16 `json:"code"`
	Msg string `json:"msg"`
}

func (m *Err) GetProtoId() uint16 {
	return 1
}

func (m *Err) Marshal(w *csbuf.CsbufParser) {
	w.SetUint16(m.Proto, 1)
	w.SetUint16(m.Code, 2)
	w.SetString(m.Msg, 3)
}

func (m *Err) Unmarshal(r *csbuf.CsbufParser) {
	m.Proto = r.GetUint16(1)
	m.Code = r.GetUint16(2)
	m.Msg = r.GetString(3)
}

func NewErr() csbuf.CsbufMessage {
	return &Err{}
}